#include<vector>
#include"room.hpp"
#include"session.hpp"
#include"matcher.hpp"
#include"server.hpp"
#define HOST "192.168.217.131"
#define USER "root"
#define PASS "1234567899"
#define DBNAME "gobang"
#define PORT 3306
void mysql_test()
{
    MYSQL* mysql = mysql_util::mysql_create(HOST,USER,PASS,DBNAME,PORT);
    std::string sql = std::string("insert stu values(null,'小蓝',98,44,98);") ; 
    bool ret = mysql_util::mysql_exec(mysql,sql);
    if(ret == false)
    {
        ELOG("mysql exec failed");
        mysql_util::mysql_destroy(mysql);
        return ;
    }

    mysql_util::mysql_destroy(mysql);
}
void json_test()
{
    Json::Value root;
    root["姓名"] = "张三";
    root["年龄"] = 18;
    root["性别"] = "男";
    root["成绩"].append(98);
    root["成绩"].append(88);
    root["成绩"].append(78);
    std::string ret ;
    json_util::serialize(root,ret);
    DLOG("%s",ret.c_str());

    Json::Value root1;
    json_util::unserialize(ret,root1);
    std::cout<<std::endl;
    // 访问root1中的数据
    std::string name = root1["姓名"].asString();
    std::cout<<"姓名:"<<name<<std::endl;
    std::cout<<"age:"<<root1["年龄"].asInt()<<std::endl;
    std::string sex = root1["性别"].asString();
    std::cout<<"性别:"<<sex<<std::endl;
    int sz =root1["成绩"].size();
    for(int i = 0;i<sz;i++)
    {
        std::cout<<root1["成绩"][i].asInt()<<std::endl;
    }
}
void str_test()
{
    std::string str = ",,,,,,,,,,,,.......123213,321321,4234,,,43243,2,3,4,4,5,6,7,8,9";
    std::vector<std::string> vec;

    string_util::split(str,",",vec);
    for(auto& e: vec)
    {
        std::cout<<e<<std::endl;
    }
}
void file_test()
{
    std::string body;
    std::string filename = "gobang.cc";
    file_util::read(filename,body);
    std::cout<<body<<std::endl;
}
void db_test()
{
    user_table ut(HOST,USER,PASS,DBNAME,PORT);
    Json::Value user;
    user["username"] = "小a";
    user["password"] = "123456";
    // bool ret = ut.insert(user);
    // if(ret == false)
    // {
    //     ELOG("insert user failed");
    //     return ;
    // }
    bool ret = ut.login(user);
    if(ret == false)
    {
        ELOG("login user failed");
        return ;
    }
    ret = ut.select_by_name("小a",user);
    if(ret == false)
    {
        ELOG("select by name failed");
        return ;
    }
    std::string body;
    json_util::serialize(user,body);
    DLOG("%s",body.c_str());
    ret = ut.select_by_id(1,user);
    if(ret == false)
    {
        ELOG("select by id failed");
        return ;
    }
    std::string body1;
    json_util::serialize(user,body1);
    DLOG("%s",body1.c_str());

    

    ut.win(1);
    ut.lose(1);
    ut.lose(1);


    
}

int main()
{
    
    // LOG("%s,%d,%s","hello world", 123,"fdsfdsf");
    // LOG("fdsfds");
    // ILOG("hello world");
    // DLOG("hello world");
    // ELOG("hello world");
    // json_test();
    // str_test();

    // file_test();
    // db_test();
    
    // user_table ut(HOST,USER,PASS,DBNAME,PORT);
    // online_manager om;
    // room_manager rm(&ut,&om);
    // room_ptr rp = rm.create_room(1,2);
    // if(rp.get() == nullptr)
    // {
    //     ELOG("create room failed");
    //     return -1;
    // }
    // matcher mc(&rm,&ut,&om);


    gobang_server _server(HOST,USER,PASS,DBNAME,PORT);
    _server.start(9002); // 设置监听端口
    
    return 0;

}